import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/shipMemberDividend/shipMemberDividend/list',
  save = '/shipMemberDividend/shipMemberDividend/add',
  edit = '/shipMemberDividend/shipMemberDividend/edit',
  deleteOne = '/shipMemberDividend/shipMemberDividend/delete',
  deleteBatch = '/shipMemberDividend/shipMemberDividend/deleteBatch',
  importExcel = '/shipMemberDividend/shipMemberDividend/importExcel',
  exportXls = '/shipMemberDividend/shipMemberDividend/exportXls',
  getPrice = '/shipMemberDividend/shipMemberDividend/obtainTheUnitPricePerShareForThisWeek',
  distributionOperationManually = '/shipMemberDividend/shipMemberDividend/distributionOperationManually',
  addFen = '/shipEquitySettings/shipEquitySettings/add',
  listFen = '/shipEquitySettings/shipEquitySettings/list',
  addAll = '/shipEquitySettings/shipEquitySettings/addAll',
  getAmountByTime = '/shipDividendAmountLog/shipDividendAmountLog/getAmountByTime',
  amountLoglist = '/shipDividendAmountLog/shipDividendAmountLog/list',
  queryTheTotalRecommendedIncomeAmount = '/memberIncome/memberIncome/queryTheTotalRecommendedIncomeAmount',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({ url: Api.list, params });
export const amountLoglist = (params) =>
  defHttp.get({ url: Api.amountLoglist, params });

export const queryTheTotalRecommendedIncomeAmount = (params) =>
  defHttp.get({ url: Api.queryTheTotalRecommendedIncomeAmount, params });

export const listFen = () =>
  defHttp.get({ url: Api.listFen });
export const getPrice = (params) =>
  defHttp.get({ url: Api.getPrice, params });
export const distributionOperationManually = (params) => {
  return defHttp.get({ url: Api.distributionOperationManually, params })
}

/**
 * 删除单个
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
}
export const addAll = (params) => {
  let url = Api.addAll;
  return defHttp.post({ url: url, params });
}
export const getAmountByTime = (params) => {
  let url = Api.getAmountByTime;
  return defHttp.get({ url: url, params });
}

export const addFen = (params) => {

  return defHttp.post({ url: Api.addFen, params });
}